<script>
	import http from '@/utils/http';
	import api from '@/api';
	import {
		getAllPrivacySetting
		// getOpenid
	} from '@/utils/index.js'
	import {
		mapMutations,
		mapActions,
		mapState
	} from 'vuex';
	export default {
		version: '5.1.2', // 版本号
		globalData: {
			baseURL: 'https://74cmsse.tywangcai.com/v1_0',
			imgUlr: 'https://74cmsse.tywangcai.com/static/applet/'
		},
		onLaunch: function() {},
		methods() {},
		// 会多次触发
		onShow: function() {
			let loginInfo = uni.getStorageSync('loginInfo');
			if (loginInfo != '') {
				this.$store.commit('setLoginState', loginInfo);
			}
			// 判断是否有配置信息
			const globalConfig = this.$store.state.config
			if (!globalConfig) {
				try {
					this.$store.dispatch('getConfig')
				} catch (error) {
					Notify(error.message || 'Has Error')
				}
			}
			this.connectWs();
		},
		// 会多次触发
		onHide: function() {
			this.setImToken('');
			if (this.$ws.socketTask != null) {
				this.$ws.completeClose();
			}
		},
		mounted() {
			// #ifdef MP-WEIXIN
			this.setPlatform('miniprogram')
			getAllPrivacySetting()
			// getOpenid()
			// #endif
			// #ifdef MP-ALIPAY
			my.setNavigationBar({
				frontColor: '#000000',
				backgroundColor: '#f8f8f8',
			})
			// #endif
			// #ifdef MP-TOUTIAO
			this.setPlatform('tiktok')
			// #endif
		},
		// 捕获异常
		onError: function(err) {},
		computed: {
			...mapState(['loginInfo', 'imToken', 'LoginOrNot'])
		},
		methods: {
			...mapMutations(['setImToken','setPlatform']),
			...mapActions(['initWebSocket', 'webSocket_send']),
			// ********* 获取imToken
			getImToken() {
				http.get(api.imToken).then(res => {
					this.setImToken(res.data.data);
					this.$ws.init(res.data.data);
					this.initWebSocket(res.data.data)
				});
			},
			// ********* 全局检测聊天是否开启
			imWindowGlobal() {
				http.post(api.im_window_global).then((res) => {
					if (res.data.next == '') {
						this.getImToken()
					}
				})
			},
			connectWs() {
				if (this.LoginOrNot) {
					if (this.imToken) {
						if (this.$ws.socketTask == null) {
							this.$ws.init(this.$store.state.imToken);
						}
					} else if (this.imToken == '') {
						this.getImToken();
					}
				}
			}
		}
	};
</script>

<style lang="scss">
	@import './static/css/base.css';
	@import './static/css/resetForm.css';
	@import 'uview-ui/index.scss';

	page {
		height: 100%;
		background-color: #fff;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		box-sizing: border-box;
	}

	.pageBg {
		/* #ifdef MP-WEIXIN || APP-PLUS */
		background: #f7f7f7 url('./static/img/publicBg.png') no-repeat top center;
		min-height: 100vh;
		/* #endif */
		/* #ifdef MP-TOUTIAO || MP-ALIPAY */
		background: #f7f7f7 url('./static/img/publicBgTrill.png') no-repeat top center;
		min-height: 100%;
		/* #endif */
		background-size: 100% 512rpx;
	}

	.login_con {
		.u-drawer-content {
			width: 100% !important;
		}
	}

	.index_popup {
		.u-mode-center-box {
			background-color: transparent !important;
		}
	}

	.u-loadmore {
		.u-load-more-wrap {
			height: 80rpx !important;
		}
	}

	.btn_group {
		.btn_mb {
			.u-btn {
				margin-bottom: 32rpx !important;
			}
		}
	}

	.jobTag_con {
		.u-drawer-content {
			height: 90% !important;
		}
	}

	.map_con {
		.u-drawer-content {
			height: 90% !important;
		}
	}

	//
	.u-dropdown__menu__item {
		width: 25%;

		.u-flex {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.u-dropdown__menu__item__text {
			display: block;
			overflow: hidden !important;
			white-space: nowrap !important;
			text-overflow: ellipsis !important;
		}
	}

	.u-empty {
		padding: 200rpx 0;
		background: #fff;
		// background:red;
		border-radius: 14rpx;
	}

	.u-label {
		flex: 0 0 200rpx !important;
	}

	.form-line {
		display: flex;
		padding: 28rpx 28rpx;
		background: #fff;
		font-family: PingFang SC, -apple-system, sans-serif;

		.form-field {
			flex: 1.3;
			display: flex;
			// font-weight: 400;
			font-family: PingFang SC, -apple-system, sans-serif;

			.label {
				width: 208rpx;
				position: relative;
				font-weight: 400;
				font-family: PingFang SC, -apple-system, sans-serif;

				&::before {
					content: '*';
					position: absolute;
					left: -16rpx;
					font-size: 22rpx;
					color: #fa3534;
					top: 50%;
					transform: translateY(-50%);
				}

				&.no::before {
					display: none;
				}
			}

			.text {
				width: 450rpx;
				flex-shrink: 0;
				white-space: nowrap;
				overflow-x: auto;
				font-size: 14px;
				font-family: PingFang SC, -apple-system, sans-serif;
				color: #333;

				&.ac {
					color: #757575;
					font-family: PingFang SC, -apple-system, sans-serif;
				}
			}
		}

		.arrow-icon {
			display: flex;
			align-items: center;
			justify-content: center;
			// padding: 0 20rpx;
		}
	}

	.textarea {
		width: 100%;
		height: 292rpx;
		border: 0;
		background-color: #f9f9f9;
		font-size: 28rpx;
		resize: none;
		padding: 16rpx 30rpx;
		line-height: 1.8;
		color: #303133;
		font-family: PingFang SC, -apple-system, sans-serif;
		text-align: start;
		word-wrap: break-word;
		overflow-y: auto;

		&.textarea-color {
			color: #757575;
			font-family: PingFang SC, -apple-system, sans-serif;
		}
	}

	.textarea2 {
		width: calc(100% - 60rpx);
		height: 260rpx;
		border: 0;
		background-color: #f9f9f9;
		font-size: 28rpx;
		resize: none;
		padding: 16rpx 30rpx;
		line-height: 1.8;
		color: #757575;
		font-family: PingFang SC, -apple-system, sans-serif;
		text-align: start;
		word-wrap: break-word;
		overflow-y: auto;

		&.textarea-color {
			color: #303133;
			font-family: PingFang SC, -apple-system, sans-serif;
		}
	}

	.u-field,
	.u-dropdown {
		background-color: #fff;
	}

	.placeholder {
		font-size: 50rpx;
	}

	.addJobTips {
		text-align: center;
		padding: 35rpx 25rpx;
		font-size: 30rpx;
		color: #606266;
		padding-top: 240rpx;
		background: url(./static/img/customer-dialog.png);
		background-size: 100% 152rpx;
		background-position: top center;
		background-repeat: no-repeat;

		.text1,
		.text2 {
			color: #1b1a1a;
			font-size: 36rpx;
		}

		.text2 {
			margin-bottom: 50rpx;
			margin-top: 20rpx;
		}

		.text3 {
			font-size: 46rpx;
			color: #ff6600;
			margin-bottom: 30rpx;
		}

		.text4 {
			color: #999999;
			font-size: 28rpx;
		}
	}

	.POPUP_PADDING {
		padding: 40rpx 20rpx;
	}

	// 职聊相关
	::v-deep .im-item-box {
		padding-bottom: 60rpx;
	}

	::v-deep .im-item {
		display: flex;
		font-size: 28rpx;
		height: 100%;

		.photo {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;

			image {
				width: 100%;
				height: 100%;
				border-radius: 50%;
			}
		}

		.is-read {
			font-size: 26rpx;

			&.read {
				// 已读
				color: #c8c8c8;
			}

			&.service {
				//送达
				color: #1887fb;
			}
		}
	}

	::v-deep .im-time {
		text-align: center;
		padding: 0rpx 0 28rpx 0;
		color: #999999;
		font-size: 26rpx;
	}

	::v-deep .im-time:first-child {
		padding-top: 48rpx;
	}

	::v-deep .im-left {
		flex-direction: row;
		margin-left: 30rpx;

		.photo {
			margin-right: 26rpx;
		}

		.is-read {
			margin-left: 20rpx;
		}
	}

	::v-deep .im-right {
		margin-right: 30rpx;
		flex-direction: row-reverse;

		.photo {
			margin-left: 26rpx;
		}

		.is-read {
			margin-right: 20rpx;
		}
	}

	.substring1 {
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
</style>